package com.abc.easyclaim;

import java.io.File;
import java.util.Date;

import com.abc.bean.Case;
import com.abc.bean.Template;
import com.abc.db.DBManager;
import com.abc.tool.StringTool;
import com.baidu.mapapi.c;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;

public class SplashActivity extends Activity {
	
	private static final long SPLASH_DISPLAY_LENGHT = 2000;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		new Handler().postDelayed(new Runnable() {
			public void run() {
				//首次运行加载数据库
				if(MainApplication.getConfigData().getIsFirstStart()){
					Log.d("sys", "first install");
					MainApplication.getConfigData().setIsFirstStart(false);
					initLocalSqlLite();
				}
				// 检查SDcard
				// 检查网络等等
				startActivity(new Intent(SplashActivity.this, CaseListActivity.class));
				SplashActivity.this.finish();
			}

		}, SPLASH_DISPLAY_LENGHT);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.splash, menu);
		return true;
	}
	
	/**
	 * 首次安装，初始化数据库数据
	 */
	private void initLocalSqlLite(){
		//删除原有数据库
		String dbPath=android.os.Environment.getExternalStorageDirectory()
				 .getAbsolutePath()+"/database";
		File dbp=new File(dbPath);
        File dbf=new File(dbPath+"/"+"easyclaim.db");
        dbf.delete();
        
		DBManager mgr = new DBManager(this);
		Case caze =new Case();
		caze.setName("王先生的理赔");
		caze.setAccidentDate("2013-7-21 9:30:00");
		caze.setLastModifyDate("2013-7-22 14:10:00");
		caze.setCarNumber("鄂A19890");
		caze.setCarOwnerName("王大牛");
		caze.setCarOwnerPhone("13987654678");
		caze.setCarOwnerAddr("武汉洪山区幸福小区6号203室");
		caze.setInsuranceNumber("PA01002055");
		caze.setNote("我的备注");
		caze.setOfficerName("张小明");
		caze.setOfficerNumber("ZD000001");
		caze.setImportant("false");
		caze.setLocation("109,37");
		caze.setCarBrand("AUDI");
		mgr.addCase(caze);
		
		caze.setName("赵先生的理赔");
		caze.setAccidentDate("2013-7-23 10:40:00");
		caze.setLastModifyDate("2013-7-24 15:30:00");
		caze.setCarNumber("鄂A11001");
		caze.setCarOwnerName("赵胜");
		caze.setCarOwnerPhone("13998896666");
		caze.setCarOwnerAddr("武汉洪山区幸福小区6号203室");
		caze.setInsuranceNumber("PA01002056");
		caze.setNote("我的备注");
		caze.setOfficerName("张小明");
		caze.setOfficerNumber("ZD000001");
		caze.setImportant("false");
		caze.setLocation("129,37");
		caze.setCarBrand("BMW");
		mgr.addCase(caze);
		
		caze.setName("陈先生的理赔");
		caze.setAccidentDate("2013-7-21 9:30:00");
		caze.setLastModifyDate("2013-7-22 14:10:00");
		caze.setCarNumber("123");
		caze.setCarOwnerName("鄂A12222");
		caze.setCarOwnerPhone("13911112222");
		caze.setCarOwnerAddr("武汉江夏区银河湾1号601室");
		caze.setInsuranceNumber("PA01002057");
		caze.setNote("我的备注");
		caze.setOfficerName("张小明");
		caze.setOfficerNumber("ZD000001");
		caze.setImportant("false");
		caze.setLocation("139,36");
		caze.setCarBrand("BUICK");
		mgr.addCase(caze);
		
		Template template = new Template();
		template.setContent("事故的起因");
		mgr.addTemplate(template);
		template.setContent("相关的损失");
		mgr.addTemplate(template);
		template.setContent("相关资料的完整性");
		mgr.addTemplate(template);
	}
}
